<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            height: 100px;
        }

        .container1 .box1 {
            background: red;
            display: block;
        }

        .container1 .box2 {
            background: blue;
            display: none;
        }

        .container1 .box3 {
            background: yellow;
            display: none;
        }
    </style>
</head>

<body>
    div <div class="container1">
        <button>按钮一</button>
        <button>按钮二</button>
        <button>按钮三</button>
        <div class="box1"></div>
        <div class="box2"></div>
        <div class="box3"></div>
    </div>
    <script>
        // 面向过程,注重过程
        //获取全部button
        let btns =document.querySelectorAll(".container1 button");
        //获取全部div
        let divs = document.querySelectorAll(".container1  div");
        //遍历所有button,每一项绑定点击事件
        //遍历所有div
        //判断按钮的索引和div的索引一样,就显示,不一样就隐藏
        btns.forEach((item,key)=>item.onclick=()=>divs.forEach((div,k)=>key===k?div.style.display="block":div.style.display="none"))
    </script>
</body>

</html>